package com.senarai.tempedroid;

import org.json.JSONObject;


import com.senarai.tempedroid.Connection;

import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        Connection c = new Connection();
		
		JSONObject jsonObject = c.getItem(2);
		String[] attributes = null;
		try {
			attributes = new String[] {
				String.valueOf(jsonObject.getInt("id")),
				String.valueOf(jsonObject.getInt("kategori_id")),
				jsonObject.getString("nama"),
				jsonObject.getString("path_gambar"),
				jsonObject.getString("deskripsi"),
				String.valueOf(jsonObject.getInt("harga_satuan"))
			};
		} catch (Exception e) {
			// TODO: handle exception
			Log.i("", e.toString());
			System.out.println("error " + e.toString());
		}
		
		
        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, attributes));
        getListView().setTextFilterEnabled(true);
        
    }
    
    protected void onListItemClick(ListView l, View v, int position, long id) {
    	super.onListItemClick(l, v, position, id);
    	Object o = this.getListAdapter().getItem(position);
    	String attribute = o.toString();
    	Toast.makeText(this, "You have chosen the attribute: " + " " + attribute, Toast.LENGTH_LONG).show();
    }
}